﻿#pragma once

#include "common.h"
#include "ui/ui.h"
#include "ui/button.h"
#include "ui/menu.h"

namespace anip
{
	namespace ui
	{
		class MenuSeparatorItem : public Menu::Item
		{
		public:
			MenuSeparatorItem(Menu& m) : Menu::Item(m) {}

			void paint() override;
			void flow(Flow& f) override;
		};

		class MenuTextItem : public WithText<Menu::Item>
		{
		private:
			Menu* _subMenu = nullptr;

		protected:
			void processMouseEnter() override;
			void processMouseLeave() override;
			void processMouseButton(MouseButton btn, ButtonAction action) override;

		public:
			enum class CheckState
			{
				NoCheck, Unchecked, Checked
			};

			MenuTextItem(Menu& m, const wstring& text, CheckState ch = CheckState::NoCheck);

			std::function<void(MenuTextItem& self)> onClick;
			std::function<Menu* (MenuTextItem& self)> getSubMenu;

			bcolor hoverColor = r::MenuItem_HoverColor;
			bfloat pressFactor = r::Button_PressFactor;
			bool enabled = true;
			CheckState check;

			void paint() override;
			void flow(Flow& f) override;
		};

		class MenuLabelItem : public WithText<Menu::Item>
		{
		public:
			MenuLabelItem(Menu& m, const wstring& text);

			void paint() override;
			void flow(Flow& f) override;
		};

		class MenuRadioBarItem;

		class MenuRadioBarSubItem : public Selectable<MenuRadioBarItem>
		{
			friend class MenuRadioBarItem;

		private:
			wstring _text{};
			bool _hovered = false, _pressed = false;
			Texture2D* _tex = nullptr;

			MenuRadioBarSubItem(MenuRadioBarItem& parent) :
				Selectable(parent) {}
			Texture2D* getTex();

		public:
			MenuRadioBarSubItem(const MenuRadioBarSubItem& obj) = default;
			~MenuRadioBarSubItem();
			void setText(const wstring& text);
			wstring getText() { return _text; };

			bool isHovered() const { return _hovered; }

			std::function<void(MenuRadioBarSubItem& self)>
				onClick;
		};

		class MenuRadioBarItem : public SelectableContainer<Menu::Item, MenuRadioBarSubItem>
		{
		protected:
			void processMouseMove(invec2 pos) override;
			void processMouseLeave() override;
			void processMouseButton(MouseButton btn, ButtonAction action) override;

			int _hoveredIndex = -1;

		public:
			bcolor 
				textColor = r::TextColor,
				backColor = r::MenuRadioBar_BackColor,
				selectedColor = r::Button_SelectedColor,
				hoverColor = r::MenuItem_HoverColor;

			bfloat 
				pressFactor = r::Button_PressFactor,
				hoverFactor = r::Button_HoverFactor;

			MenuRadioBarItem(Menu& m) : SelectableContainer(m) {}

			MenuRadioBarSubItem& addItem(const wstring& text);
			int hoveredIndex() const;

			void paint() override;
			void flow(Flow& f) override;
		};
	}
}